<?php
class String {

	function __construct() {
	}

	public static function escKoreaChange($str) {
		$str = preg_replace("/&(#?[0-9a-zA-Z]{2,7});/", "__sina_\\1_word__", $str);
		return $str;
	}

	/* 把字符串中已经转换省略形态的韩文,恢复成韩文.eg:__sina_#44444_word__->&#44444
	* @param string $str
	* @return string
	* @author huiliang<huiliang@staff.sina.com.cn>
	*/
	public static function escKoreaRestore($str) {
		$str = preg_replace("/__sina_(#?[0-9a-zA-Z]{2,7})_word__/U", "&\\1;", $str);
		return $str;
	}
	/**
	* 过滤字符串中的HTML标记 < >
	* @param string $str 需要过滤的字符
	* @return string
	* @author huiliang<huiliang@staff.sina.com.cn>
	*/
	public static function unHtml($str) {
		$s = array (
			"&" => "&amp;",
			"<" => "&lt;",
			">" => "&gt;",
			"\n" => "<br>",
			"\t" => "&nbsp;&nbsp;&nbsp;&nbsp;",
			"\r" => "",
			" " => "&nbsp;",
			"\"" => "&quot;",
			"'" => "&#039;"
		);
		$str = self :: escKoreaChange($str);
		$str = strtr($str, $s);
		$str = self :: escKoreaRestore($str);
		return $str;
	}
}
?>